#-*- codeing = utf-8 -*-
#@Time : 2020/10/29 13:30
#@Author : 阳某
#@File : 二叉树遍历.py
#@Software : PyCharm

# python实现字符串复制
def func(path,node):
    path = path + '->'+node
    print('in function',path)
path = 'root'
print('not in function',path)

func(path,'left')
print('not in function',path)

func(path,'right')
print('not in function',path)


class Solution:
    def binaryPaths(self,root: TreeNode) ->List[str]:
        paths = []
        self._dfs(root,'',paths)
        return paths
    def _dfs(self,root:TreeNode,path:str,paths:List[str]):
        if not root:
            return
        path += str(root.val)
        if not root.left and not root.right:
            paths.append(path)
            return
        path = path +'->'
        self._dfs(root.left,path,paths)
        self._dfs(root.right,path,paths)